package phaseTest01;

import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

public class ThreadPool {

	public static void main(String[] args) {
//		ExecutorService pool1 = Executors.newFixedThreadPool(2);
//		pool1.execute(new MyRun("AAA"));
//		pool1.execute(new MyRun("BBB"));
//		pool1.execute(new MyRun("CCC"));
//		pool1.execute(new MyRun("DDD"));
		
		//定时启动，(线程运行，时间，时间，时间单位）
		ScheduledExecutorService pool2 = Executors.newScheduledThreadPool(2);
		pool2.scheduleAtFixedRate(new YourRun(), 5,2, TimeUnit.SECONDS);
		
		
	}

}


class YourRun implements Runnable{
	int count = 0;
	@Override
	public void run() {
		// TODO Auto-generated method stub
		System.out.println("working........"+(++count));
	}
}

class MyRun implements Runnable {

	private String name;

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public MyRun(String name) {
		super();
		this.name = name;
	}

	@Override
	public void run() {
		// TODO Auto-generated method stub
		for (int i = 0; i < 100; i++) {
			try {
				Thread.sleep(2);
			} catch (InterruptedException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			System.out.println(this.getName()+ "......running.......");
		}
	
	}

}